package cn.wolfcode.book.dao.impl;

import cn.wolfcode.book.dao.BookDAO;
import cn.wolfcode.book.entity.Book;
import cn.wolfcode.entity.BookQueryObject;
import org.junit.Test;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author 李新雨的项目86176
 * @version 1.0
 * @date 2024-10-26 11:25
 */
public class BookDAOImplTest {
    private BookDAO bookDAO = new BookDAOImpl();

    @Test
    public void add() {
        Book book = new Book();
        book.setBname("了不起的盖茨比");
        book.setAuthor("F·斯科特·菲茨杰拉德");
        book.setSalePrice(new BigDecimal(656));
        book.setCostPrice(new BigDecimal(198));
        book.setClassify(11L);
        bookDAO.add(book);
    }

    @Test
    public void delById() {
//      bookDAO.delById(7L);
        Book book=new Book();
        System.out.println(book);
    }

    @Test
    public void edit() {
        Book book = new Book();
        book.setId(3L);
        book.setBname("哈姆雷特3");
        book.setAuthor("莎士比亚");
//        book.setSalePrice(new BigDecimal(56));
//        book.setCostPrice(new BigDecimal(10));
//        book.setClassify(1L);
        bookDAO.edit(book);
    }

    @Test
    public void selOneById() {
        Book book = bookDAO.selOneById(1L);
        System.out.println(book);
    }

    @Test
    public void selAll() {
        List<Book> books = bookDAO.selAll();
        for (Book book : books) {
            System.out.println(book);
        }
    }

    @Test
    public  void  selConditionAll(){
        BookQueryObject bookQueryObject=new BookQueryObject();
        bookQueryObject.setKeyword("莎");
//        bookQueryObject.setMinSalePrice(new BigDecimal(200));
//        bookQueryObject.setMaxSalePrice(new BigDecimal(300));
        List<Book> books = bookDAO.selConditionAll(bookQueryObject);
        for (Book book : books) {
            System.out.println(book);
        }
    }
}